<?php 
if(!defined('X_SMILEYS_HTTPPATH'))         define('X_SMILEYS_HTTPPATH',         HTTP_ROOT     . "/images/smileys/");
if(!defined('X_SMILEYS_DEFINITIONSFILE'))  define('X_SMILEYS_DEFINITIONSFILE',  DOCUMENT_ROOT . "/images/smileys/smileys.txt");
if(!defined('X_SMILEYS_CSSCLASS'))         define('X_SMILEYS_CSSCLASS',         "X_smileys");


class X_smileys extends X{
    public static function text($MSG){
        $smileys= stripslashes(file_get_contents(X_SMILEYS_DEFINITIONSFILE));
        foreach(preg_split("/[\n]+/",$smileys) as $smiley){
            $SmileyArray= preg_split("/[\r\t	 ]+/",$smiley);
                foreach($SmileyArray as $replaceChars){
                    if($replaceChars != $SmileyArray[0] && $replaceChars != "") $MSG= X_smileys::encode($SmileyArray[0],$replaceChars,$MSG);
                }
        }
        return $MSG;
    }
    public static function encode($name,$chars,$MSG){
        return preg_replace("#".preg_quote($chars,"#")."#","<img class=\"".X_SMILEYS_CSSCLASS."\" title=\"".$chars."\" alt=\"\" src=\"".X_SMILEYS_HTTPPATH.$name."\" />",$MSG);
    }
    public static function renderSmiley($name, $chars, $elementID){
        echo "<a href=\"javascript:addSmiley('".str_replace("'","\\'",$chars)."','".$elementID."');void(0);\"><img class=\"".X_SMILEYS_CSSCLASS."\" title=\"".$chars."\" alt=\"\" src=\"".X_SMILEYS_HTTPPATH.$name."\" /></a>";
    }
    public static function renderSmileys($elementID,$FirstSmiley=0,$NumberOfSmileys=0){
        $smileys= stripslashes(file_get_contents(X_SMILEYS_DEFINITIONSFILE));
        $i=0;
        foreach(preg_split("/[\n]+/",$smileys) as $smiley){
            if($i < $NumberOfSmileys || $NumberOfSmileys == 0){
                $SmileyArray= preg_split("/[\r\t	 ]+/",$smiley);
                foreach($SmileyArray as $replaceChars){
                    if($replaceChars != $SmileyArray[0] && $replaceChars != "" && $i >= $FirstSmiley) {X_smileys::renderSmiley($SmileyArray[0],$replaceChars, $elementID);break;}
                }
                $i++;
            }else{
                break;
            }
        }
    }
    
    
}




?>
<script type="text/javascript"><!-- // Smileys Functions
    function addSmiley(chars,textareaID){
	document.getElementById(textareaID).focus();
	document.getElementById(textareaID).value= document.getElementById(textareaID).value + chars + ' ';
	document.getElementById(textareaID).focus();
    }
// -->
</script>
<style type="text/css">
    .X_smileys {
	border: none !important;
	margin: 0px 2px 0px 2px !important;
	width: 24px !important;
	height: 24px !important;
        float: none !important;
    }
</style>
